#include <Windows.h>
#include <intrin.h>
#define DLLEXPORT_TEMPLATE(define, name, ...)\
_declspec(dllexport) define					 \
{											 \
	return name(__VA_ARGS__);				 \
}											 \

extern void AsmVmwareCall(unsigned long out[4], unsigned short cmd, unsigned short param1, unsigned long param2);

#pragma warning(disable:4098)
DLLEXPORT_TEMPLATE(unsigned char InByte(unsigned short addr), __inbyte, addr);
DLLEXPORT_TEMPLATE(void InByteString(unsigned short addr, unsigned char* string, unsigned long length), __inbytestring, addr, string, length);
DLLEXPORT_TEMPLATE(unsigned short InWord(unsigned short addr), __inword, addr);
DLLEXPORT_TEMPLATE(unsigned long InDword(unsigned short addr), __indword, addr);
DLLEXPORT_TEMPLATE(void OutByte(unsigned short addr, unsigned char data), __outbyte, addr, data);
DLLEXPORT_TEMPLATE(void OutByteString(unsigned short addr, unsigned char* string, unsigned long length), __outbytestring, addr, string, length);
DLLEXPORT_TEMPLATE(void OutWord(unsigned short addr, unsigned short data), __outword, addr, data);
DLLEXPORT_TEMPLATE(void OutDword(unsigned short addr, unsigned long data), __outdword, addr, data);
DLLEXPORT_TEMPLATE(void Cpuid(int outInfo[4], int eax, int ecx), __cpuidex, outInfo, eax, ecx);
_declspec(dllexport) unsigned char VmwareCall(unsigned long out[4], unsigned short cmd, unsigned short param1, unsigned long param2)
{
	__try
	{
		AsmVmwareCall(out, cmd, param1, param2);
		return TRUE;
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		return FALSE;
	}
}
